package com.fjjn.component;

import jodd.util.concurrent.ThreadFactoryBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class DelayQueueThreadPoolExecutorConfig {

    /**
     * 延迟队列线程池，队列满了把新的丢弃的拒绝策略
     * @return
     */
    @Bean
    @ConditionalOnBean({RedissionDelayQueueService.class})
    public ThreadPoolExecutor delayQueueThreadPoolExecutor(){
        return new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(1000), new ThreadFactoryBuilder().setNameFormat("delay-queue-pool-%d").get());

    }
}
